// Copyright (c) Kurrent, Inc and/or licensed to Kurrent, Inc under one or more agreements.
// Kurrent, Inc licenses this file to you under the Kurrent License v1 (see LICENSE.md).

using System.Reactive.Subjects;
using EventStore.Plugins.Licensing;
using Microsoft.IdentityModel.JsonWebTokens;

namespace KurrentDB.Plugins.TestHelpers;

public static class Fixtures {
	static readonly Dictionary<string, string> _hardCodedTokens = new() {
		{ "AUTO_SCAVENGE", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJlc2RiIiwiaXNzIjoiZXNkYiIsImV4cCI6MTgyNDQ1NjgyOCwianRpIjoiMTU3NDk2N2MtMmVkNC00OGZhLWIyNjItYTdhMGQzYTA1NTczIiwic3ViIjoiRVNEQiBUZXN0cyIsIklzVHJpYWwiOiJUcnVlIiwiSXNFeHBpcmVkIjoiRmFsc2UiLCJJc1ZhbGlkIjoiVHJ1ZSIsIklzRmxvYXRpbmciOiJUcnVlIiwiRGF5c1JlbWFpbmluZyI6IjEiLCJTdGFydERhdGUiOiIyNi8wNC8yMDI0IDAwOjAwOjAwICswMTowMCIsIkFVVE9fU0NBVkVOR0UiOiJ0cnVlIiwiaWF0IjoxNzI5ODQ4ODI4LCJuYmYiOjE3Mjk4NDg4Mjh9.jaQ58MxlqM2oORJw9bWJzvdTzwWxFeo-624SMN52Rm2j6HLvWsT2_jFTb_Xi-rXmP1C7KlJCQEMhksV_5QdsiRi37oao1fcxfywOBHQkPMqx2Hd1CMWq1_DAY0az12fRSrR9h3L_yIiez2coRNFKkc5mZSq2KHoZre0WWXbMUDL1RheG1KNTxL2qBelyYVMYRZ7lXfsUpgzahOTR36QTtWYETBbtzik8ZujINhYGUhqbGLtGO3Ad3kTqPQVB6MMDNgE6F-ZHLMrXPR08fJNYrkxcB8WoSbelzPduPN6tMJeyn1e6jYO3oOUBZZsD2tdX_Pai1qw4fiZlZlPycbYOBQ" },
		{ "ENCRYPTION_AT_REST", "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXV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UiOiJ0cnVlIiwiaWF0IjoxNzI5ODQ4ODI5LCJuYmYiOjE3Mjk4NDg4Mjl9.R24i-ZAow3BhRaST3n25Uc_nQ184k83YRZZ0oRcWbU9B9XNLRH0Iegj0HmkyzkT50I4gcIJOIfcO6mIPp4Y959CP7aTAlt7XEnXoGF0GwsfXatAxy4iXG8Gpya7INgMoWEeN0v8eDH8_OVmnieOxeba9ex5j1oAW_FtQDMzcFjAeErpW__8zmkCsn6GzvlhdLE4e3r2wjshvrTTcS_1fvSVjQZov5ce2sVBJPegjCLO_QGiIBK9QTnpHrhe6KCYje6fSTjgty0V1Qj22bftvrXreYzQijPrnC_ek1BwV-A1JvacZugMCPIy8WvE5jE3hVYRWGGUzQZ-CibPGsjudYA" },
	};

	public class FakeLicenseService : ILicenseService {
		public FakeLicenseService(bool createLicense = true, string? entitlement = null) {
			var license = new License(new JsonWebToken(_hardCodedTokens[entitlement ?? "NONE"]));
			SelfLicense = license;

			if (createLicense) {
				CurrentLicense = license;
				Licenses = new BehaviorSubject<License>(license);
			} else {
				var licenses = new Subject<License>();
				licenses.OnError(new Exception("no license"));
				Licenses = licenses;
			}
		}

		public License SelfLicense { get; }

		public License? CurrentLicense { get; }

		public IObservable<License> Licenses { get; }

		public void RejectLicense(Exception ex) {
			RejectionException = ex;
		}

		public Exception? RejectionException { get; private set; }
	}
}
